import request from '@/request';
import {PAGE_SIZE} from '../constants';
import querystring from 'querystring';
const ENTITY = 'role';
//定义一个注册的方法,调用api接口
export function list(pageNum=1,where={}){//{username:'zhufeng'} username=zhufeng
  let whereString = querystring.stringify(where);
  return request(`/api/${ENTITY}?pageNum=${pageNum}&pageSize=${PAGE_SIZE}&${whereString}`);
}

export function create(values){
  return request(`/api/${ENTITY}`,{
    method:'POST',
    body:JSON.stringify(values)
  });
}

export function update(values){
  return request(`/api/${ENTITY}/${values.id}`,{
    method:'PUT',
    body:JSON.stringify(values)
  });
}
export function del(id){
  return request(`/api/${ENTITY}/${id}`,{
    method:'DELETE'
  });
}
export function delAll(ids){
  return request(`/api/${ENTITY}/${ids[0]}`,{
    method:'DELETE',
    body:JSON.stringify(ids)
  });
}

export function getResources(){
  return request(`/api/getResources`);
}

export function setResources(roleId,resourceIds){
  return request(`/api/setResources`,{
    method:'POST',
    body:JSON.stringify({roleId,resourceIds})
  });;
}

export function getUsers(){
  return request(`/api/getUsers`);
}

export function setUsers(roleId,userIds){
  return request(`/api/setUsers`,{
    method:'POST',
    body:JSON.stringify({roleId,userIds})
  });;
}